package com.atjinggu.jinggumail.product.controller;

import java.util.Arrays;
import java.util.Map;

import com.atjinggu.jinggumail.product.vo.AttrVo;
import com.atjinggu.jinggumail.product.vo.RespAttrVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.atjinggu.jinggumail.product.service.AttrService;
import com.atjinggu.jinggumail.common.utils.PageUtils;
import com.atjinggu.jinggumail.common.utils.R;



/**
 * 商品属性
 *
 * @author jingming
 * @email jingming@gmail.com
 * @date 2020-12-13 00:06:45
 */
@RestController
@RequestMapping("product/attr")
public class AttrController {
    @Autowired
    private AttrService attrService;


    //http://localhost:9001/api/product/attr/sale/list/225?t=1608810804973&page=1&limit=500


    /**
     * 列表
     *
     * http://localhost:9001/api/product/attr/base/list/0?t=1608619958301&page=1&limit=10&key=
     */
    @RequestMapping("/{attrType}/list/{categoryId}")
    //@RequiresPermissions("product:attr:list")
    public R list(@RequestParam Map<String, Object> params,@PathVariable Integer categoryId,@PathVariable("attrType")String type){
        PageUtils page = attrService.queryAttrList(params,categoryId,type);
        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{attrId}")
    //@RequiresPermissions("product:attr:info")
    public R info(@PathVariable("attrId") Long attrId){
		RespAttrVo attr = attrService.getDetailById(attrId);

        return R.ok().put("attr", attr);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    //@RequiresPermissions("product:attr:save")
    public R save(@RequestBody AttrVo attr){
		attrService.saveAttr(attr);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    //@RequiresPermissions("product:attr:update")
    public R update(@RequestBody RespAttrVo attrVo){
		attrService.updateAttrById(attrVo);
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //@RequiresPermissions("product:attr:delete")
    public R delete(@RequestBody Long[] attrIds){
		attrService.removeByIds(Arrays.asList(attrIds));

        return R.ok();
    }

}
